#include "PaintBrush.h"
QColor PaintBrush::brushColor = Qt::blue;
int PaintBrush::brushSize = 2;

void PaintBrush::mousePressEvent(QMouseEvent* event, PaintArea  *ourImage)
{
                       if(ourImage->getUndoPointer() == -1)
                                 ourImage->saveUndoState();
						
	ourImage->setLastPoint(ourImage->mapFromScene(ourImage->mapFromScene(event->pos())));
                         ourImage->setScribbling(true);

}
void PaintBrush::mouseMoveEvent(QMouseEvent* event, PaintArea  *ourImage)
{

        drawLineTo(ourImage->mapFromScene(ourImage->mapFromScene(event->pos())), ourImage);
}


void  PaintBrush::mouseReleaseEvent(QMouseEvent *event, PaintArea  *ourImage)
 {
     if (event->button() == Qt::LeftButton ) {
		 drawLineTo(ourImage->mapFromScene(ourImage->mapFromScene(event->pos())), ourImage);

     }

 }

void PaintBrush::drawLineTo(const QPoint &endPoint, PaintArea  *ourImage)
 {
	
	QImage* yup = ourImage->getImage();
	QPainter painter(yup);

	const QPen pen(brushColor, brushSize, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin);
	painter.setPen(pen);

	painter.drawLine(ourImage->getLastPoint(), endPoint);
	//ourImage->modified = true;
	
	int rad = (brushSize / 2) + 2;

	ourImage->updatePixmap();
	ourImage->setLastPoint(endPoint); 
        
 }
